package com.freight.user.controller;

import com.freight.core.common.utils.PageUtil;
import com.freight.core.common.utils.ResultUtil;
import com.freight.core.common.vo.PageVo;
import com.freight.core.common.vo.Result;
import com.freight.core.common.vo.SearchVo;
import com.freight.file.vo.PicFileVo;
import com.freight.user.entity.DriverLicense;
import com.freight.user.service.DriverLicenseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author huyingtai
 */
@Slf4j
@RestController
@Api(description = "驾驶证管理接口")
@RequestMapping("/freight/driverLicense")
@Transactional
public class UserDriverLicenseController {

    @Autowired
    private DriverLicenseService driverLicenseService;


    @RequestMapping(value = "/getByCondition", method = RequestMethod.GET)
    @ApiOperation(value = "多条件分页获取")
    public Result<Page<DriverLicense>> getByCondition(DriverLicense driverLicense, SearchVo searchVo, PageVo pageVo) {

        Page<DriverLicense> page = driverLicenseService.findByCondition(driverLicense, searchVo, PageUtil.initPage(pageVo));
        return new ResultUtil<Page<DriverLicense>>().setData(page);
    }



    @RequestMapping(value = "/upLoadDriverLicense", method = RequestMethod.POST)
    @ApiOperation(value = "上传驾照图片")
    public Result<PicFileVo> upLoadDriverLicense(@RequestParam(required = false) MultipartFile file, String fileType, Long userId) {

        PicFileVo res = driverLicenseService.upLoadDriverLicense(file, fileType,userId);
        return ResultUtil.data(res);
    }

    @RequestMapping(value = "/getDriverLicenseInfo", method = RequestMethod.POST)
    @ApiOperation(value = "获取驾照相关信息")
    public Result<DriverLicense> getDriverLicenseInfo(Long userId) {
        DriverLicense res = driverLicenseService.getDriverLicenseInfo(userId);
        return ResultUtil.data(res);
    }

}
